package com.zrwl.poscloud.xo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.entity.*;
import com.zrwl.poscloud.base.enums.EBusiType;
import com.zrwl.poscloud.base.enums.EBusinessType;
import com.zrwl.poscloud.base.enums.ESourceType;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.global.Constants;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.*;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import com.zrwl.poscloud.xo.mapper.*;
import com.zrwl.poscloud.xo.service.*;
import com.zrwl.poscloud.xo.vo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 账户业务表 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-10-20
 */
@Service
public class EmployeeAccountRecordServiceImpl extends SuperServiceImpl<EmployeeAccountRecordMapper, EmployeeAccountRecord> implements EmployeeAccountRecordService {

    /***
     * 操作员日志类型固定为5
     */
    final static int adminLogType = 5;

    @Autowired
    private EmployeeAccountRecordService employeeAccountRecordService;
    @Autowired
    private SequenceService sequenceService;
    @Autowired
    private AdminService adminService;
    @Resource
    private EmployeeAccountRecordMapper employeeAccountRecordMapper;

    @Resource
    EmployeeAccountMapper employeeAccountMapper;
    @Resource
    UserEmployeeRMapper userEmployeeRMapper;
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private EmployeeAccountService employeeAccountService;
    @Autowired
    private EmployeeAccountLogService employeeAccountLogService;
    @Autowired
    private AdminLogService adminLogService;
    @Autowired
    private MessageWxService messageWxService;
    @Autowired
    UserService userService;
    @Resource
    private DeptMapper deptMapper;
    public static String url = "http://localhost:8607/pos-admin/employeeAccountRecord/lostCardToStatus";

    @Override
    public IPage<EmployeeAccountRecordVO> getPageList(EmployeeAccountRecordVO employeeAccountRecordVO) {
        Page<EmployeeAccountRecordVO> page = new Page<>();
        page.setCurrent(employeeAccountRecordVO.getCurrentPage());
        page.setSize(employeeAccountRecordVO.getPageSize());
        IPage<EmployeeAccountRecordVO> pageList = employeeAccountRecordMapper.getPageList(page, employeeAccountRecordVO);
        List<EmployeeAccountRecordVO> list = pageList.getRecords();
        pageList.setRecords(list);
        return pageList;
    }

    @Override
    public List<EmployeeAccountRecord> getAllList(EmployeeAccountRecordVO employeeAccountRecordVO) {
        QueryWrapper<EmployeeAccountRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<EmployeeAccountRecord> list = employeeAccountRecordService.list(queryWrapper);
        return list;
    }


    @Override
    public String add(EmployeeAccountRecordVO employeeAccountRecordVO) {
        EmployeeAccountRecord entity = employeeAccountRecordService.getById(employeeAccountRecordVO.getUid());
        BeanUtils.copyProperties(employeeAccountRecordVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }

    @Override
    public String edit(EmployeeAccountRecordVO employeeAccountRecordVO) {
        EmployeeAccountRecord entity = employeeAccountRecordService.getById(employeeAccountRecordVO.getUid());
        BeanUtils.copyProperties(employeeAccountRecordVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }

    @Override
    public String delete(EmployeeAccountRecordVO employeeAccountRecordVO) {
        EmployeeAccountRecord entity = employeeAccountRecordService.getById(employeeAccountRecordVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }


    //开户业务
    @Override
    public void createAccount(EmployeeAccountRecordVO employeeAccountRecordVO, AdminVO adminVO) {
        /***
         * 1.查找余额账户, 每次必然是对余额账户的处理
         * 2.构建record记录内容
         * 3.根据不同的业务类型进行分别操作
         *  3.1构建目标账户
         *  3.2创建目标账户的变动记录
         *  3.2.1目标账户的变动记录造成对应的卡记录
         * 4.保存业务记录
         * 5.保存操作日志
         */
        EmployeeVO employeeVO = new EmployeeVO();
        try {
            BeanConvertorUtil.convertor(employeeAccountRecordVO, employeeVO);
        } catch (Exception e) {
            log.error("参数传递出错，无法创建持卡人信息", e);
            throw new RuntimeException("参数传递出错，无法创建持卡人信息");
        }
        employeeVO.setSourceType(Constants.EMPLOYEE_ADMIN);
        employeeVO.setSourceUid(adminVO.getUid());
        employeeService.add(employeeVO);
        employeeAccountRecordVO.setEmployeeUid(employeeVO.getUid());
        // 创建电子钱包账户
        EmployeeAccountVO employeeAccountVO = new EmployeeAccountVO();
        employeeAccountVO.setEmployeeUid(employeeVO.getUid());
        employeeAccountVO.setType(Constants.EMPLOYEE_ACCOUNT_AMT);//电子钱包账户类型
        if(employeeAccountRecordVO.getGiftAccountType() == 1){
            employeeAccountVO.setBalance(employeeAccountRecordVO.getCashAmt()+employeeAccountRecordVO.getRchargeGiftAmt());
        }else {
            employeeAccountVO.setBalance(employeeAccountRecordVO.getCashAmt());
        }
        try {
            employeeAccountVO = employeeAccountService.employeeAccountBuild(employeeAccountVO);
            employeeAccountRecordVO.setAccountUid(employeeAccountVO.getUid());
            employeeAccountRecordVO.setAmtType(Constants.INCREASE_AMOUNT);
            employeeAccountRecordVO.setSummary(employeeAccountRecordVO.getBusiType().getName() + ",初始余额: " + employeeAccountRecordVO.getCashAmt()+",赠送金额: "+employeeAccountRecordVO.getRchargeGiftAmt());
        } catch (Exception e) {
            log.error("余额账户构建异常", e);
            throw new RuntimeException(employeeAccountRecordVO.getBusiType().getName() + "-余额账户构建异常");
        }
        Map<String, Double> allAccountBalances = employeeAccountService.getAllAccountBalances(employeeVO.getUid());
        employeeAccountRecordVO.setBalanceAmt(allAccountBalances.get("balance_amt"));
        employeeAccountRecordVO.setBalanceCount(allAccountBalances.get("count_amt") == null?0:allAccountBalances.get("count_amt").intValue());
        employeeAccountRecordVO.setSubsidyAmt(allAccountBalances.get("subsidy_amt") == null?0:allAccountBalances.get("subsidy_amt"));
        employeeAccountRecordVO.setSecondAmt(allAccountBalances.get("second_amt") == null?0:allAccountBalances.get("second_amt"));
        employeeAccountRecordVO.setGiftAmt(allAccountBalances.get("gift_amt") == null?0:allAccountBalances.get("gift_amt"));
        employeeAccountRecordVO.setBalanceFeeAmt(allAccountBalances.get("fee_amt") == null?0:allAccountBalances.get("fee_amt"));
        employeeAccountRecordVO.setCashGiftAmt(employeeAccountRecordVO.getRchargeGiftAmt());
        employeeAccountRecordVO.setCashGiftType(employeeAccountRecordVO.getGiftAccountType());
        employeeAccountRecordVO.setCompanyUid(adminVO.getCompanyUid());
        //办理记录保存
        createRecord(employeeAccountRecordVO, adminVO);
        //账户log保存，包括卡信息的变动和卡log保存
        EmployeeAccountLogVO employeeAccountLogVOFrom = new EmployeeAccountLogVO();
        employeeAccountLogVOFrom.setSourceUid(employeeAccountRecordVO.getUid());
        employeeAccountLogVOFrom.setSourceType(4);//账户业务默认
        employeeAccountLogVOFrom.setAccountUid(employeeAccountVO.getUid());
        employeeAccountLogVOFrom.setBeforeBalance(0);
        employeeAccountLogVOFrom.setAmt(employeeAccountRecordVO.getCashAmt());
        employeeAccountLogVOFrom.setType(Constants.INCREASE_AMOUNT);
        employeeAccountLogVOFrom.setBalanceAmt(employeeAccountRecordVO.getBalanceAmt());
        employeeAccountLogVOFrom.setSubsidyBalanceAmt(employeeAccountRecordVO.getSubsidyAmt());
        employeeAccountLogVOFrom.setBalanceCount(employeeAccountRecordVO.getBalanceCount());
        employeeAccountLogVOFrom.setSecondAmt(employeeAccountRecordVO.getSecondAmt());
        employeeAccountLogVOFrom.setGiftAmt(employeeAccountRecordVO.getGiftAmt());
        employeeAccountLogVOFrom.setFeeAmt(employeeAccountRecordVO.getBalanceFeeAmt());
        employeeAccountLogVOFrom.setSummary(employeeAccountRecordVO.getSummary());
        employeeAccountVO.setCompanyUid(adminVO.getCompanyUid());
        createAccountLogAndCardLog(employeeAccountLogVOFrom, employeeAccountVO, employeeAccountRecordVO.getBusiType().getType(),deptMapper.getCompanyNameByCompanyCode(employeeAccountRecordVO.getCompanyCode()));
        //操作日志保存
        createAdminLog("开通账户", 1, employeeAccountRecordVO, AdminLogVO.OPERATIONTYPE.CREATE, adminVO, null, employeeAccountRecordVO);
        if(employeeAccountRecordVO.getGiftAccountType() == 1){
            employeeAccountRecordVO.setCashAmt(employeeAccountRecordVO.getRchargeGiftAmt());
            createAdminLog("充值赠送", 0, employeeAccountRecordVO, AdminLogVO.OPERATIONTYPE.CREATE, adminVO, null, null);
        }

        if(employeeAccountRecordVO.getGiftAccountType() == 2){
            EmployeeAccountVO employeeAccountGiftVO = new EmployeeAccountVO();
            try {
                employeeAccountGiftVO.setEmployeeUid(employeeAccountVO.getEmployeeUid());
                employeeAccountGiftVO.setType(Constants.EMPLOYEE_ACCOUNT_GIFT_AMT);//赠送账户类型
                employeeAccountGiftVO = employeeAccountService.employeeAccountBuild(employeeAccountGiftVO);
            } catch (Exception e) {
                log.error("赠送账户构建异常", e);
                throw new RuntimeException(employeeAccountRecordVO.getBusiType().getName() + "-赠送账户构建异常");
            }
            //账户log保存，包括卡信息的变动和卡log保存
            EmployeeAccountLogVO employeeAccountLogVOGift = new EmployeeAccountLogVO();
            employeeAccountLogVOGift.setSourceUid(employeeAccountRecordVO.getUid());
            employeeAccountLogVOGift.setSourceType(4);//账户业务默认
            employeeAccountLogVOGift.setAccountUid(employeeAccountGiftVO.getUid());
            employeeAccountLogVOGift.setBeforeBalance(employeeAccountGiftVO.getBalance());
            employeeAccountLogVOGift.setAmt(employeeAccountRecordVO.getRchargeGiftAmt());
            employeeAccountLogVOGift.setGiftAmt(employeeAccountRecordVO.getGiftAmt());
            employeeAccountLogVOGift.setType(Constants.INCREASE_AMOUNT);
            employeeAccountLogVOGift.setBalanceAmt(employeeAccountRecordVO.getBalanceAmt());
            employeeAccountLogVOGift.setSubsidyBalanceAmt(employeeAccountRecordVO.getSubsidyAmt());
            employeeAccountLogVOGift.setBalanceCount(employeeAccountRecordVO.getBalanceCount());
            employeeAccountLogVOGift.setSecondAmt(employeeAccountRecordVO.getSecondAmt());
            employeeAccountLogVOGift.setGiftAmt(employeeAccountRecordVO.getGiftAmt());
            employeeAccountLogVOGift.setFeeAmt(employeeAccountRecordVO.getBalanceFeeAmt());
            employeeAccountRecordVO.setCashAmt(employeeAccountRecordVO.getRchargeGiftAmt());
            employeeAccountLogVOGift.setSummary(employeeAccountRecordVO.getBusiType().getName());
            DecimalFormat df = new DecimalFormat("#0.00");
            double giftBalance = Double.parseDouble(df.format(employeeAccountGiftVO.getBalance() + employeeAccountRecordVO.getRchargeGiftAmt()));
            employeeAccountGiftVO.setBalance(giftBalance);
            employeeAccountGiftVO.setCompanyUid(adminVO.getCompanyUid());
            createAccountLogAndCardLog(employeeAccountLogVOGift, employeeAccountGiftVO, employeeAccountRecordVO.getBusiType().getType(),deptMapper.getCompanyNameByCompanyCode(employeeAccountRecordVO.getCompanyCode()));
            createAdminLog("", 0, employeeAccountRecordVO, AdminLogVO.OPERATIONTYPE.CREATE, adminVO, null, null);
        }
    }

    //编辑业务
    @Override
    public void editAccount(EmployeeAccountRecordVO employeeAccountRecordVO, AdminVO adminVO) {
        /***
         * 判断是否人员信息发生变动
         * 1.查找余额账户, 每次必然是对余额账户的处理
         * 2.构建record记录内容
         * 3.根据不同的业务类型进行分别操作
         *  3.1构建目标账户
         *  3.2创建目标账户的变动记录
         *  3.2.1目标账户的变动记录造成对应的卡记录
         * 4.保存业务记录
         * 5.保存操作日志
         */
        boolean editCard = false;
        boolean editEmployee = false;
        EmployeeVO employeeVO = new EmployeeVO();
        Employee employee = employeeService.getById(employeeAccountRecordVO.getEmployeeUid());
        try {
            BeanConvertorUtil.convertor(employeeAccountRecordVO, employeeVO);
        } catch (Exception e) {
            log.error("参数传递出错，无法转义持卡人信息", e);
            throw new RuntimeException("参数传递出错，无法转义持卡人信息");
        }
        if (!employeeVO.getCompanyCode().equals(employee.getCompanyCode())) {
            editEmployee = true;
            editCard = true;
        }
        if (!employeeVO.getName().equals(employee.getName())) {
            editEmployee = true;
            editCard = true;
        }
        if (employeeVO.getCertCode() != null || employee.getCertCode() != null) {
            if (!employeeVO.getCertCode().equals(employee.getCertCode()))
                editEmployee = true;
        }
        if (employee.getLabelDataUid() != null) {
            if (!employee.getLabelDataUid().equals(employeeVO.getLabelDataUid()))
                editEmployee = true;
        } else if (employeeVO.getLabelDataUid() != null) {
            editEmployee = true;
        }
        if (employeeVO.getBirthday() != employee.getBirthday())
            editEmployee = true;
        if (employeeVO.getSex() != employee.getSex())
            editEmployee = true;
        if (employeeVO.getPayLevel() != employee.getPayLevel()) {
            editEmployee = true;
            editCard = true;
        }
        if (!Objects.equals(employeeVO.getMobile(), employee.getMobile()))
            editEmployee = true;
        if (!Objects.equals(employeeVO.getRemark(), employee.getRemark()))
            editEmployee = true;
        if (employeeVO.getIsFacePayment() != employee.getIsFacePayment())
            editEmployee = true;
        if ((employee.getEnterDate() == null && employeeVO.getEnterDate() != null) || (employeeVO.getEnterDate().getTime() != employee.getEnterDate().getTime()))
            editEmployee = true;
        //卡的限额是独立设置的，当联机交易时账户限额生效，卡限额只在脱机交易时生效。换句话说卡限额有可能大于账户限额。
        //这里有一个优化空间，就是查询各个卡的限额，让卡限额大于联机限额
        if (employeeVO.getDailyLimit() != employee.getDailyLimit()) {
            editEmployee = true;
        }
        if (employeeVO.getMonthlyLimit() != employee.getMonthlyLimit()) {
            editEmployee = true;
        }
        employeeAccountRecordVO.setCompanyUid(adminVO.getCompanyUid());
        if (editEmployee) {
            // 电子钱包账户
            EmployeeAccountVO employeeAccountVO = new EmployeeAccountVO();
            employeeAccountVO.setEmployeeUid(employeeAccountRecordVO.getEmployeeUid());
            employeeAccountVO.setType(Constants.EMPLOYEE_ACCOUNT_AMT);//电子钱包账户类型
            employeeAccountVO = employeeAccountService.employeeAccountFind(employeeAccountVO);
            if (employeeAccountVO == null)
                throw new RuntimeException(employeeAccountRecordVO.getBusiType().getName() + "-余额账户不存在");
            //办理记录保存
            employeeAccountRecordVO.setBeforeAmt(employeeAccountVO.getBalance());
            employeeAccountRecordVO.setSummary("修改持卡人信息或账户参数");
            createRecord(employeeAccountRecordVO, adminVO);
            employeeService.edit(employeeVO);
            //操作日志保存
            createAdminLog("修改账户", 0, employeeAccountRecordVO, AdminLogVO.OPERATIONTYPE.UPDATE, adminVO, employee, employeeVO);
        }

    }

    //离开业务
    @Override
    public void leaveAccount(EmployeeAccountRecordVO employeeAccountRecordVO, AdminVO adminVO) {
        EmployeeVO employeeVO = new EmployeeVO();
        employeeVO.setUid(employeeAccountRecordVO.getEmployeeUid());
        Employee employee = employeeService.getById(employeeVO.getUid());
        if (employee.getStatus() == 2) {
            throw new RuntimeException("该持卡人已经离开");
        }
        Date LeaveDate = new Date();
        employee.setStatus(EStatus.FREEZE);
        employee.setLeaveDate(LeaveDate);
        employee.updateById();
        employeeAccountRecordVO.setCompanyUid(adminVO.getCompanyUid());
        employeeAccountRecordVO.setCompanyCode(employee.getCompanyCode());
        employeeAccountRecordVO.setEmployeeCertCode(employee.getCertCode());
        employeeAccountRecordVO.setEmployeeName(employee.getName());
        employeeAccountRecordVO.setEmployeeCode(employee.getEmployeeCode());
        // 电子钱包账户
        EmployeeAccountVO employeeAccountVO = new EmployeeAccountVO();
        employeeAccountVO.setEmployeeUid(employeeAccountRecordVO.getEmployeeUid());
        employeeAccountVO.setType(Constants.EMPLOYEE_ACCOUNT_AMT);//电子钱包账户类型
        employeeAccountVO = employeeAccountService.employeeAccountFind(employeeAccountVO);
        if (employeeAccountVO != null){
            employeeAccountRecordVO.setAccountUid(employeeAccountVO.getUid());
        }
        //办理记录保存
        employeeAccountRecordVO.setBeforeAmt(employeeAccountVO.getBalance());
        employeeAccountRecordVO.setSummary("持卡人离开");
        createRecord(employeeAccountRecordVO, adminVO);
        //操作日志保存
        createAdminLog("人员离开", 0, employeeAccountRecordVO, AdminLogVO.OPERATIONTYPE.UPDATE, adminVO, null, null);
//        挂失所有卡
        handleRemoteLostCardToStatus(employeeAccountRecordVO);
    }

    private void handleRemoteLostCardToStatus(EmployeeAccountRecordVO employeeAccountRecordVO) {
        String str = JsonUtils.objectToJson(employeeAccountRecordVO);
        HttpRequestUtil.sendPost2(url,str);
    }

    /***
     * 保存操作员操作日志
     * @param employeeAccountRecordVO
     * @param adminVO
     */
    void createAdminLog(String keyword1, int resEmployeeCount, EmployeeAccountRecordVO employeeAccountRecordVO, AdminLogVO.OPERATIONTYPE operationType, AdminVO adminVO, Object oldData, Object newData) {
        //创建日志
        try {
            AdminLogVO adminLogVO = new AdminLogVO(
                    AdminLogVO.LOGLEVEL.REPORT,
                    adminLogType,
                    operationType,
                    employeeAccountRecordVO.getSummary(),
                    oldData, newData,
                    keyword1,//业务名称
                    employeeAccountRecordVO.getCompanyCode(),
                    employeeAccountRecordVO.getEmployeeCode(),
                    employeeAccountRecordVO.getEmployeeName(),
                    employeeAccountRecordVO.getOnLineAmt(),//在线提现金额
                    employeeAccountRecordVO.getOffLineAmt(),//线下提现
                    keyword1.equals("账户提现") ? 0d : employeeAccountRecordVO.getCashAmt(),//现金收入
                    0d,//手续费
                    0d, 0d,
                    1,//业务条数
                    resEmployeeCount,//人员资源
                    0);//卡片资源

            adminLogVO.setAdminUid(adminVO.getUid());
            adminLogVO.setName(adminVO.getNickName());
            adminLogVO.setSourceType(ESourceType.icl_employeeAccountRecord.getType());
            adminLogVO.setSourceName(ESourceType.icl_employeeAccountRecord.getName());
            adminLogVO.setSourceUid(employeeAccountRecordVO.getUid());
            adminLogService.log(adminLogVO);
        } catch (Exception e) {
            log.error(employeeAccountRecordVO.getBusiType().getName() + "-日志异常", e);
            throw new RuntimeException(employeeAccountRecordVO.getBusiType().getName() + "-日志异常");
        }
    }

    /***
     * 将业务操作记录保存到数据库，初始化业务编号信息
     * @param employeeAccountRecordVO
     * @param adminVO
     * @throws Exception
     */
    public void createRecord(EmployeeAccountRecordVO employeeAccountRecordVO, AdminVO adminVO) {
        String ownerUid = null;
        Integer ownerType = null;
        if (adminVO == null)
            throw new RuntimeException("系统错误：操作员为空");
        if (adminVO.isCompany()) {
            ownerType = 2;
            ownerUid = adminVO.getCompanyUid();
        } else {
            throw new RuntimeException("非商户操作员，禁止使用此功能");
        }

        EmployeeAccountRecord entity = new EmployeeAccountRecord();
        BeanUtils.copyProperties(employeeAccountRecordVO, entity, SysConf.CREATE_TIME, SysConf.UPDATE_TIME);
        if (entity.getStatus() == 0) entity.setStatus(EStatus.ENABLE);
        SequenceVO sequenceVO = new SequenceVO();
        sequenceVO.setOwnerType(ownerType);
        sequenceVO.setOwnerUid(ownerUid);
        sequenceVO.setBusiType(employeeAccountRecordVO.getBusiType());
        Sequence sequence = sequenceService.customizeSelect(sequenceVO);

        if (sequence == null) {
            throw new RuntimeException("系统错误：编号队列读取失败");
        } else {
            String code = sequenceService.generateSerialCode(sequence);
            entity.setCode(code);
            entity.setAdminUid(adminVO.getUid());
            entity.setAdminName(adminVO.getNickName());
            if (entity.insert()) {
                employeeAccountRecordVO.setUid(entity.getUid());
            }
        }
        //发送微信消息
        UserEmployeeRVO userEmployeeRVO = userEmployeeRMapper.getCurrentFollowersByEmployeeUid(employeeAccountRecordVO.getEmployeeUid());
        if (userEmployeeRVO != null) {
            User user = userService.getById(userEmployeeRVO.getUserUid());
            MessageWxVO messageWxVO = new MessageWxVO();
            messageWxVO.setModelType(2);
            messageWxVO.setToUid(user.getUid());
            String businessName = employeeAccountRecordVO.getBusiType().getName().split("-")[1] + "业务";
            messageWxVO.setFirst(businessName + "已完成");
            String remark = employeeAccountRecordVO.getCashAmt() != 0 ? employeeAccountRecordVO.getBusiType().getName().split("-")[1] + "现金金额" + employeeAccountRecordVO.getCashAmt() : "";
            messageWxVO.setRemark(remark);
            //从模板配置中获取
            messageWxVO.setTemplateId("enWLs4pr_XwlF0raEwnT-g1gGHINEF069pW_GIIcOiw");
            messageWxVO.setContent(businessName + "," + employeeAccountRecordVO.getEmployeeName() + "," + DateUtils.formateDate(employeeAccountRecordVO.getCreateTime(), "yyyy年MM月dd日 HH时mm分ss秒") + ",已完成");
            messageWxVO.setUrl("http://wx.yucard.cn");
            messageWxVO.setOpenId(user.getWeChat());
            messageWxService.add(messageWxVO);
            //触发一次发送
          /*  messageWxService.sendMessage(messageWxVO);*/
        }
    }
    /***
     * 账户log保存，包括卡信息的变动和卡log保存 仅包含金额发生变动的业务
     * @param employeeAccountLogVO
     * @throws Exception
     */
    @Override
    public void createAccountLogAndCardLog(EmployeeAccountLogVO employeeAccountLogVO, EmployeeAccountVO employeeAccountVO, int cardLogBusinessType,String deptName) {
        //账户变动日志
        if (!employeeAccountLogService.add(employeeAccountLogVO)) {
            throw new RuntimeException("账户变动记录保存异常");
        }
        if (!employeeAccountService.edit(employeeAccountVO)) {
            throw new RuntimeException("账户信息保存异常");
        }
    }
    @Override
    public EmployeeAccountRecordVO employeeVOShiftEmployeeAccountRecordVO(EmployeeAccountRecordVO
                                                                                  employeeAccountRecordVO, EmployeeVO employeeVO) {
        try {
            BeanConvertorUtil.reverseConvertor(employeeVO, employeeAccountRecordVO);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return employeeAccountRecordVO;
    }
}
